#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int N = 2e5 + 10;
int a[N], b[N], c[N];
int n;

int main()
{
	int t;
	cin >> t;
	//cout << "==" << (5 & 7 & 12 & 6) << endl;
	while (t--) {
		cin >> n;
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		int x = a[1];
		bool flag = 0;
		int z = 0;
		bool flag1 = 0;
		for (int i = 2; i <= n; i++) {
			if (flag) {
				flag = 0;
				x = a[i];
				continue;
			}
			x &= a[i];
			if (!x && i != n - 1) {
				ans++;
				flag = 1;
			}
			else if (!x && i == n - 1) {
				flag1 = 1;
				break;
			}
		}
		if (flag1) {
			if ((a[n - 1] & a[n]) == 0)ans++;
		}
		//cout << "x==" << x << endl;
		//b[1] = a[1];
		//for (int i = 2; i <= n; i++) {
		//	b[i] = b[i - 1] & a[i];
		//}
		//c[n] = a[n];
		//for (int i = n - 1; i >= 1; i--) {
		//	c[i] = c[i + 1] & a[i];
		//}
		//for (int i = 1; i <= n; i++) {
		//	cout << "i==" << i << endl;
		//	cout << "b[i-1]==" << b[i - 1] << endl;
		//	cout << "c[i+1]==" << c[i + 1] << endl;
		//	if ((i == 1 || !b[i - 1]) && ((i == n) || !c[i + 1])) {
		//		/*cout << "i==" << i << endl;
		//		cout << "b[i-1]==" << b[i - 1] << endl;
		//		cout << "c[i+1]==" << c[i + 1] << endl;*/
		//		ans++;
		//	}
		//}
		cout << ans << endl;
	}
	return 0;
}